package com.smartplatform.service.impl;

import com.smartplatform.mapper.SysUserOnlineMapper;
import com.smartplatform.pojo.SysUserOnline;
import com.smartplatform.service.SysUserOnlineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author 咕唧
 * @Date 2022/5/29 20:02
 * @Version 1.0
 */
@Service
@Transactional
public class SysUserOnlineServiceImpl implements SysUserOnlineService {

    private SysUserOnlineMapper sysUserOnlineMapper;

    @Autowired
    public void setSysUserOnlineMapper(SysUserOnlineMapper sysUserOnlineMapper) {
        this.sysUserOnlineMapper = sysUserOnlineMapper;
    }

    /**
     * 添加设备在线状态信息
     * @param sysUserOnline
     */
    @Override
    public void insertUserOnline(SysUserOnline sysUserOnline) {
        //查询数据是否存在
        String sessionId = sysUserOnlineMapper.findByUsername(sysUserOnline.getLoginName());
        if (sessionId != null) {
            //有数据先删除
            sysUserOnlineMapper.deleteByUsername(sysUserOnline.getLoginName());
        }
        //添加数据
        sysUserOnlineMapper.insertOnline(sysUserOnline);
    }
}
